package com.yuhuofei2021.spring.boot.weather.job;

import java.util.List;
import javax.annotation.Resource;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.yuhuofei2021.spring.boot.weather.entity.City;
import com.yuhuofei2021.spring.boot.weather.service.CityDataService;
import com.yuhuofei2021.spring.boot.weather.service.WeatherDataService;
/**
 * @description 
 * @author yuhuofei2021
 * @date 2021年9月20日
 */
public class WeatherDataSyncJob extends QuartzJobBean {

	private final static Logger logger = LoggerFactory.getLogger(WeatherDataSyncJob.class);
	
	@Resource
	private CityDataService cityDataService;
	
	@Resource
	private WeatherDataService weatherDataService;
	
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		logger.info("=============自动查询天气信息环节开始！===========");
		//获取城市id列表
		List<City> cityList = null;
		try {
			cityList = cityDataService.listCity();
		} catch (Exception e) {
			logger.error("获取城市列表出错！",e);
		}
		
		//遍历城市id获取天气
		for (City city : cityList) {
			String cityId = city.getCityId();
			logger.info("要查询天气的城市的id是：" + cityId);
			weatherDataService.syncDataByCityId(cityId);
		}
		
		logger.info("=============自动查询天气信息环节结束！===========");
	}

}
